import 'package:flutter/material.dart';

class Ratting extends StatelessWidget {
  static const Color _colorYellow = Color(0xFFFABE00);
  static const Color _colorGrey = Color(0xFFCDCDCD);

  final int maxScore = 5;
  final int score;

  const Ratting({Key key, this.score}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    int _score = score;
    if (_score < 0) {
      _score = 0;
    } else if (_score > maxScore) {
      _score = maxScore;
    }

    Color _getColor(int index) {
      return index <= _score ? _colorYellow : _colorGrey;
    }

    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Icon(Icons.star, color: _getColor(1), size: 12),
        Icon(Icons.star, color: _getColor(2), size: 12),
        Icon(Icons.star, color: _getColor(3), size: 12),
        Icon(Icons.star, color: _getColor(4), size: 12),
        Icon(Icons.star, color: _getColor(5), size: 12),
      ],
    );
  }
}
